<?php
include_once 'dbinfo.php';

session_start();
$username = $_SESSION['username'];
$role = $_SESSION['role'];

$link = mysqli_connect($dbhost,$dbusername,$dbpassword,$dbname,$dbport);
if(!$link){
    echo "连接失败";
    die;
}

$sql = "select a.id,a.title,a.content,a.createtime,a.author from tb_articles a where isdel=0 ";
$result = mysqli_query($link,$sql);
$rowcount = mysqli_num_rows($result);

echo "用户名：$username ";
echo "角色：$role";
?>
<style>  
    table{
        border: solid 1px gray;
        border-collapse: collapse;
        margin: auto;
    }
    td{
      border: solid 1px gray;
      padding: 0px; /* 内边距 */
      margin: 0px; /* 外边距 */
      
    }

</style>  

 <script src="../js/jquery1.7.2.min.js"></script>
 <script>
    function doDel(id){
      if(confirm('确定删除吗')){
        $.post('article_del.php','id='+id,function success(res){
          //  console.log(res);
          location.reload();
        })

      }


    }
 </script>


<div class="outer">  
  <div class="content-container">  
    <table>  
      <tr>  
        <td>ID</td>  
        <td>标题</td>  
        <td>内容</td>  
        <td>发布时间</td>  
        <td>作者</td>  
        <td colspan="2">操作</td>  
      </tr>  
      <?php  
      while ($rowcount > 0 && $rows = mysqli_fetch_assoc($result)) {  
        echo "  
          <tr>  
            <td>".$rows['id']."</td>  
            <td><a href='/articles-demo1-php/php/article_detail.php?id=".$rows['id']."'>".$rows['title']."</a></td>  
            <td>".$rows['content']."</td>  
            <td>".$rows['createtime']."</td>  
            <td>".$rows['author']."</td>  
            <td><a href='/articles-demo1-php/php/article_del.php?id=".$rows['id']."'>删除</a></td>  
            <td><button onclick=doDel(".$rows['id'].")>删除</button></td>  
          </tr>  
        ";  
      }  
      mysqli_close($link);  
      ?>  
    </table>  
  </div> <!-- 结束.content-container -->  
  <div></div> <!-- 占位符，用于保持布局稳定 -->  
</div> <!-- 结束.outer -->